package com.ftg.learn.lesson4;

import java.util.Arrays;
import java.util.Random;

/**
 * 第三题
 * 生成三个不重复的数
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/6/19 下午2:33
 */
public class HomeWork {

    public static void question0301() {
        int[] as = new int[3];
        Random r = new Random();

        int index = 0;
        while (index < 3) {
            int num = r.nextInt(5);
            //比较法
            boolean isn = false;
            for (int j = 0; j < as.length; j++) {
                if (as[j] == num) {
                    isn = true;
                    break;
                }
            }

            if (!isn) {
                as[index++] = num;
            }
        }
        System.out.println(Arrays.toString(as));
    }

    public static void question0302() {
        int[] as = new int[3];
        Random r = new Random();

        int index = 0;
        do {
            int num = r.nextInt(5);
            if (index == 0) {
                as[index++] = num;
            }
            boolean isn = false;
            for (int j = 0; j < as.length; j++) {
                if (as[j] == num) {
                    isn = true;
                    break;
                }
            }

            if (!isn) {
                as[index++] = num;
            }

        } while (index < 3);
        System.out.println(Arrays.toString(as));
    }

    public static void question0303() {
        int[] as = new int[5];
        Random r = new Random();

        //表示现在生成几个
        int index = 0;
        while (index < 3) {
            int num = r.nextInt(5);
            if(as[num] == 0){
                as[num] += 1;
                index++;
            }
        }
        System.out.println(Arrays.toString(as));
    }

    public static void question0304() {
        int[] as = new int[5];
        Random r = new Random();

        //表示现在生成几个
        int index = 0;
        while (index < 3) {
            int num = r.nextInt(5);
            if(as[num] == 0){
                as[num] += 1;
                index++;
            }

        }

        for (int i = 0; i < as.length; i++) {
            if(as[i] != 0){
                System.out.println(i);
            }
        }

    }

    public static void main(String[] args) {
        question0304();
    }

}
